﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNG.LIB.Controls;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Web.UI.HtmlControls;
using System.Data;
using System.IO;
public partial class AdminPortal_Controls_HeThong_Web_Info : System.Web.UI.UserControl
{
    TblWebInfoManager _TblWebInfoManager = new TblWebInfoManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
                BindData();
        }
    }

    protected void imgbtn_Delete_Click(object sender, ImageClickEventArgs e)
    {
        string defaultImage = "";
        TblWebInfoEntity _TblWebInfoEntity = _TblWebInfoManager.SelectOne(8668);
        if (_TblWebInfoEntity != null)
        {
            if (!string.IsNullOrEmpty(_TblWebInfoEntity.LogoPath))
            {
                defaultImage = Server.MapPath(_TblWebInfoEntity.LogoPath);
                if (File.Exists(defaultImage)) File.Delete(defaultImage);
                _TblWebInfoEntity.LogoPath = "";
            }
            _TblWebInfoManager.Update(_TblWebInfoEntity);
        }
        BindData();
    }
    protected void imgbtn_delete2_Click(object sender, ImageClickEventArgs e)
    {
        string defaultImage = "";
        TblWebInfoEntity _TblWebInfoEntity = _TblWebInfoManager.SelectOne(8668);
        if (_TblWebInfoEntity != null)
        {
            if (!string.IsNullOrEmpty(_TblWebInfoEntity.BannerPath))
            {
                defaultImage = Server.MapPath(_TblWebInfoEntity.BannerPath);
                if (File.Exists(defaultImage)) File.Delete(defaultImage);
                _TblWebInfoEntity.BannerPath = "";
            }
            _TblWebInfoManager.Update(_TblWebInfoEntity);
        }
        BindData();
    }

    //load chi tiet san pham
    protected void BindToData()
    {
        string ImageDefault = "";
        //check rong
        TblWebInfoEntity _TblWebInfoEntity = _TblWebInfoManager.SelectOne(8668);
        _TblWebInfoEntity.WebName = txtName.Text;
        _TblWebInfoEntity.WebTitle = txttitle.Text;
        _TblWebInfoEntity.Keywords = txtMetakeyword.Text;
        _TblWebInfoEntity.Description = txtMetaDescription.Text;
        _TblWebInfoEntity.LogoLink = txtLnkLogo.Text;
        _TblWebInfoEntity.Policy = txtIntro.Text;
        _TblWebInfoEntity.Intro = fckGioiThieu.Value;
        _TblWebInfoEntity.ContactInfo = fckContactInfo.Value;
        _TblWebInfoEntity.SupportText = fckSupport.Value;
        _TblWebInfoEntity.Footer = fckFooter.Value;
        _TblWebInfoEntity.CreateDate = DateTime.Now;
        if (!string.IsNullOrEmpty(FileUpload1.FilePath))
        {
            ImageDefault = Server.MapPath(_TblWebInfoEntity.LogoPath);
            if (File.Exists(ImageDefault)) File.Delete(ImageDefault);
            _TblWebInfoEntity.LogoPath = FileUpload1.FilePath;
        }
        _TblWebInfoManager.Update(_TblWebInfoEntity);
    }
    protected void btnApply_Click(object sender, EventArgs e)
    {
        if (txtName.Text == "") { lblError.Text = "<img src='../Images/icon/Icon_warning.gif' alt='Cảnh báo' />  <span style='font-size:11px;color:red;'> Nhập tiêu đề tin !</span>"; txtName.Focus(); return; }
        BindToData();
        BindData();
    }

    private void BindData()
    {
        TblWebInfoEntity _TblWebInfoEntity = _TblWebInfoManager.SelectOne(8668);
        if (_TblWebInfoEntity != null)
        {
            txtName.Text = _TblWebInfoEntity.WebName;
            txttitle.Text = _TblWebInfoEntity.WebTitle;
            txtMetakeyword.Text = _TblWebInfoEntity.Keywords;
            txtMetaDescription.Text = _TblWebInfoEntity.Description;
            txtLnkLogo.Text = _TblWebInfoEntity.LogoLink;
            txtIntro.Text = _TblWebInfoEntity.Policy;
            fckGioiThieu.Value = _TblWebInfoEntity.Intro;
            fckContactInfo.Value = _TblWebInfoEntity.ContactInfo;
            fckSupport.Value = _TblWebInfoEntity.SupportText;
            fckFooter.Value = _TblWebInfoEntity.Footer;
            if (!string.IsNullOrEmpty(_TblWebInfoEntity.LogoPath))
            {
                img_logo.ImageUrl = _TblWebInfoEntity.LogoPath;
                imgbtn_Delete.ImageUrl = "~/AdminPortal/images/icon/remove_16.gif";
                imgbtn_Delete.Enabled = true;
            }
            else
            {
                img_logo.ImageUrl = "~/AdminPortal/images/icon/no_image.jpg";
                imgbtn_Delete.Enabled = false;
                imgbtn_Delete.ImageUrl = "~/AdminPortal/images/icon/remove_16_hiden.gif";
            }


        }
    }
}